package com.project.server.estates;

import com.project.common.annotation.Log;
import com.project.common.core.controller.BaseController;
import com.project.common.core.domain.AjaxResult;
import com.project.common.core.page.TableDataInfo;
import com.project.common.enums.BusinessType;
import com.project.common.utils.poi.ExcelUtil;
import com.project.server.domain.estates.TPayRule;
import com.project.server.service.estates.ITPayRuleService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 缴费规则Controller
 *
 * @author project
 * @date 2021-06-28
 */
@RestController
@RequestMapping("/server/rule")
public class TPayRuleController extends BaseController {

    @Resource
    private ITPayRuleService tPayRuleService;

/**
 * 查询缴费规则列表
 */
@PreAuthorize("@ss.hasPermi('server:rule:list')")
@GetMapping("/list")
public TableDataInfo list(TPayRule tPayRule){
    startPage();
    List<TPayRule> list = tPayRuleService.selectTPayRuleList(tPayRule);
    return getDataTable(list);
}

/**
     * 导出缴费规则列表
     */
    @PreAuthorize("@ss.hasPermi('server:rule:export')")
    @Log(title = "缴费规则", businessType = BusinessType.EXPORT)
    @GetMapping( "/export")
    public AjaxResult export(TPayRule tPayRule) {
        List<TPayRule> list = tPayRuleService.selectTPayRuleList(tPayRule);
        ExcelUtil<TPayRule> util = new ExcelUtil<TPayRule>(TPayRule. class);
        return util.exportExcel(list, "缴费规则列表");
    }

    /**
     * 获取缴费规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('server:rule:query')")
    @GetMapping(value = "/{ruleId}")
    public AjaxResult getInfo(@PathVariable("ruleId") Long ruleId) {
        return AjaxResult.success(tPayRuleService.selectTPayRuleById(ruleId));
    }

    /**
     * 新增缴费规则
     */
    @PreAuthorize("@ss.hasPermi('server:rule:add')")
    @Log(title = "缴费规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody TPayRule tPayRule) {
        return toAjax(tPayRuleService.insertTPayRule(tPayRule));
    }

    /**
     * 修改缴费规则
     */
    @PreAuthorize("@ss.hasPermi('server:rule:edit')")
    @Log(title = "缴费规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody TPayRule tPayRule) {
        return toAjax(tPayRuleService.updateTPayRule(tPayRule));
    }

    /**
     * 删除缴费规则
     */
    @PreAuthorize("@ss.hasPermi('server:rule:remove')")
    @Log(title = "缴费规则", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ruleIds}")
    public AjaxResult remove(@PathVariable Long[] ruleIds) {
        return toAjax(tPayRuleService.deleteTPayRuleByIds(ruleIds));
    }
}
